import { useEffect,useState} from "react";
import {Link} from "react-router-dom";
import { getGroupBuy } from "../../../api/purchase";
import {  Table,Button } from 'antd';
import SearchFrom from "../../../componets/SearchForm";
import dayjs from 'dayjs';
const stateType= ["0-待开始","1-预告中","2-进行中","3-已结束","4提前结束"]

 
const columns:any= [
  {
    title: '活动编号',
    dataIndex: 'id',
  },
  {
    title: '活动名称',
    dataIndex: 'name',
  },
  {
    title: '开始时间',
    dataIndex: 'startTime',
    render: (text:any) => <>{dayjs(text).format('YYYY/MM/DD HH:mm:ss')}</>,
  },
  {
    title: '结束时间',
    dataIndex: 'endTime',
    render: (text:string) => <>{dayjs(text).format('YYYY/MM/DD HH:mm:ss')}</>,
  },
  {
    title: '状态',  
    dataIndex: 'state',  
    render: (text:number) => <>{
    stateType[text]
    }</>,
  },
  {
    title: '操作',
  
    render: (row:any) => <Link to={'/admin/channel/groupBuyDetail/'+row.id}>详情</Link>,
  },
  
  
  
];
function CommunityPurchase() {
  const [search,setSearch] = useState({page:1,order:'asc',state:'',id:'',name:'',products:'',shop:'',endTime:''})
  const [groupList,setGroupList] = useState([])


  function getGroup(){
    getGroupBuy(search)
    .then(res=>{
       if(res.data.code===0){
        setGroupList(res.data.data)
       }
    })
  }
  useEffect(()=>{
    getGroup()
  },[])
  
  return ( <div>
    <div style={{paddingLeft:50}}>
      <Button><Link to="/admin/channel/createGroupBuy">创建团购活动</Link></Button>
    </div>
    <SearchFrom  search={search} setSearch={setSearch} getGroup={getGroup}></SearchFrom>
    <h3>数据列表</h3>
    <Table columns={columns} dataSource={groupList} />
  </div> );
}

export default CommunityPurchase;